import axios from 'axios';
import unit from '../unit/index'

export interface ICreateArticle {
    anthology: string
    author: string
    title: string
    content: string
}

export interface ICreateAnthology {
    anthology: string
    name: string
}

export interface IGetArticle {
    id:number
    author: string
    anthology: string
    title: string
}

export interface IGetArticleAll {
    author: string
    anthology: string
}

export interface IDeleteArticle {
    storeId:number
}

export interface IDeleteAnthology {
    storeId:number
    author:string
}

export interface IUpdateArticleText {
    title:string
    content:string
    author:string
    anthology:string
    id:number
}

export interface IUpdateArticleTitle {
    title: string
    storeId: number
}

export interface IUpdateAnthology {
    oldAnthology:string
    newAnthology:string
    author:string
}

interface IGetArticleContent {
    id:number
}

interface IRegister {
    account:string
    password:string
}

const domainName = 'http://localhost';
const port = 3002;
const host = domainName+':'+port;
const Encode = unit.Encode;
export default {
    post:{
        register:(data:IRegister)=>{return axios.post(host+'/register',Encode.encode(data))},
        login:(data:IRegister)=>{return axios.post(host+'/login',Encode.encode(data))},
        updateUserPassword:(data:IRegister)=>{return axios.post(host+'/update/user/password',Encode.encode(data))},
        uploadArticleText:(data:IUpdateArticleText)=>{return axios.post(host+'/update/article/content',Encode.encode(data))},
        uploadArticleTitle:(data:IUpdateArticleTitle)=>{return axios.post(host+'/update/article/title',Encode.encode(data))},
        uploadAnthology:(data:IUpdateAnthology)=>{return axios.post(host+'/update/anthology',Encode.encode(data))},
        createAnthology:(data:ICreateAnthology)=>{return axios.post(host+'/create/anthology',Encode.encode(data))},
        createArticle:(data:ICreateArticle)=>{return axios.post(host+'/create/article',Encode.encode(data))},
        getAnthology:()=>{return axios.post(host+'/get/anthology')},
        getArticle:(data:IGetArticle)=>{return axios.post(host+'/get/article/content',Encode.encode(data))},
        getArticleContent:(data:IGetArticleContent)=>{return axios.post(host+'/get/article/content',Encode.encode(data))},
        getArticleAll:(data:IGetArticleAll)=>{return axios.post(host+'/get/articleAll',Encode.encode(data))},
        deleteArticle:(data:IDeleteArticle)=>{return axios.post(host+'/delete/article',Encode.encode(data))},
        deleteAnthology:(data:IDeleteAnthology)=>{return axios.post(host+'/delete/anthology',Encode.encode(data))},
    }
};